<template>
  <div class="home">
    <div>
      <input type="text" v-model="keyWord" />
      <button v-on:click="search">动态参数传参查询</button>
    </div>
    <div>
      <input type="text" v-model="keyWord1" /><input
        type="text"
        v-model="keyWord2"
      /><button v-on:click="search2">跳转传参查询</button>
    </div>
    <div>
      <input type="text" v-model="keyWord3" /><button @click="search3">
        通过命名路由的方式跳转
      </button>
    </div>
  </div>
</template>

<script>
export default {
  name: "HomeView",
  data() {
    return {
      keyWord: "",
      keyWord1: "",
      keyWord2: "",
      keyWord3: "",
    };
  },
  methods: {
    search() {
      this.$router.push({
        path: "/search/" + this.keyWord,
      });
    },
    search2() {
      this.$router.push({
        // path:'/search?name='+this.keyWord1+'&age='+this.keyWord2
        // 也可以使用query配置项
        path: "/search",
        query: {
          name: this.keyWord1,
          age: this.keyWord2,
        },
      });
    },
    // 通过命名路由的方式跳转，需要在路由js中配置规则,适合路径比较长的 语法：name:'路由名'
    search3() {
      this.$router.push({
        name: "newView",
        // query: {
        //   key: this.keyWord3,
        // },
        params:{
          key:this.keyWord3
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.home {
  width: 500px;
  height: 500px;
  background-color: red;
  a {
    margin-left: 10px;
  }
}
</style>